﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@using PMP.Models
@{
    Daily daily = ViewBag.daily;
    List<Question> list = ViewBag.list;
    ViewBag.Date = "2020-06-11";
    ViewBag.Title = "日常练习 - " + ViewBag.Date;
}

<style>
    .Quest, .Questanswer {
        margin: 1em;
    }
</style>

@foreach (Question question in list)
{

    <div class="Quest">
        <div class="Questhead">
            <h3>
                @question.Title
            </h3>
            <ul>
                @foreach (Option option in question.Options)
                {
                    int isanswer = option.IsAnswer ? 1 : 0;
                    <li answer="@isanswer">
                        @option.Txt
                    </li>
                }
            </ul>
        </div>
        <div class="Questanswer">
            <p>@question.Analysis</p>
            <h3>@question.Mark</h3>
        </div>
    </div>
}





<div style="height:50px;">&nbsp;</div>
<button class="layui-btn" style="position:fixed;left:0px;bottom:0px; margin-left:1em;" onclick="last()">上一题</button>
<button class="layui-btn" style="position:fixed;right:0px;bottom:0px; margin-right:1em;" onclick="next()">下一题</button>
<script>
    $(document).ready(function () {
        $(".Quest").hide().eq(0).show().attr("curr", 1);
        //$(".Quest[curr=1]").show();
        //$(".Quest").hide().eq(0).show();
        $(".Questanswer").hide();
        $("li").each(function (idx, ele) {
            $(ele).click(function () {
                let answer = $(this).attr("answer");
                let quest = $(this).parent().parent().parent();
                if (answer == 1) {
                    $(this).css("color", "green");
                    layer.msg("回答正确", {
                        icon: 1,
                        time: 800,
                        shade: 0.3,
                        shadeClose: false
                    }, function () {
                        next();
                    });
                } else {
                    $(this).css("color", "red");
                    quest.find(".Questanswer").show();
                }
            });
        });
    });
    function last() {
        let curr = $(".Quest[curr=1]");
        let last = curr.prev(".Quest");
        if (last.length == 0) {
            layer.msg("没有上一题了");
            return;
        }
        curr.removeAttr("curr").hide();
        last.attr("curr", 1).show();
    }
    function next() {
        let curr = $(".Quest[curr=1]");
        let next = curr.next(".Quest");
        if (next.length == 0) {
            layer.msg("没有下一题了");
            return;
        }
        curr.removeAttr("curr").hide();
        next.attr("curr", 1).show();
    }
</script>
